package com.weiaibenpao.demo.chislim;

import android.content.Context;
import android.content.SharedPreferences;

import com.weiaibenpao.demo.chislim.sportoutdoor.presentation.common.BaseApplication;

public class LocationPreferences {
    private static final String LOCATION_PREFERENCES_NAME = "locationInfo";
    private static final String LOCATION_LONGITUDE = "lng";
    private static final String LOCATION_LATITUDE = "lat";
    private SharedPreferences mPref;

    public static LocationPreferences getInstance(){
        return PreferenceHolder.sInstance;
    }

    private static class PreferenceHolder{
        private static final LocationPreferences sInstance = new LocationPreferences();
    }

    private LocationPreferences() {
        Context context = BaseApplication.getAppContext();
        mPref = context.getSharedPreferences(LOCATION_PREFERENCES_NAME, Context.MODE_PRIVATE);
    }

    public String getLocationLongitude() {
        return mPref.getString(LOCATION_LONGITUDE, "");
    }

    public String getLocationLatitude() {
        return mPref.getString(LOCATION_LATITUDE, "");
    }


    public void setLocationLongitude(String longitude){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(LOCATION_LONGITUDE, longitude).apply();
    }

    public void setLocationLatitude(String latitude){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(LOCATION_LATITUDE, latitude).apply();
    }

    public void clear() {
        mPref.edit().clear().apply();
    }

}
